/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2024-10-15 16:34:55
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2024-10-15 17:17:18
 * @FilePath: /react18-vite-admin/src/service/biz/department/useDepartmentDetail.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { useStateRef } from '@/service/useStateRef';
import { DeptParam, createOrUpdateDept } from '@/api/department';

export { DeptParam };

export const useDepartmentDetail = () => {
    const [saveLoading, saveLoadingRef, setSaveLoading] = useStateRef(false);
    const saveDept = (param: DeptParam) => {
        if (saveLoadingRef.current) return Promise.reject();
        setSaveLoading(true);
        return createOrUpdateDept(param).finally(() => {
            setSaveLoading(false);
        });
    };

    return {
        saveLoading,
        setSaveLoading,
        saveDept
    };
};
